package com.matt.order.controller;

import com.github.pagehelper.util.StringUtil;
import com.matt.order.dto.CustomerDto;
import com.matt.order.dto.ProfitDto;
import com.matt.order.service.OrderEnterService;
import com.matt.order.service.ProfitListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.sqlite.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/profitList")
public class ProfitListController {

    @Autowired
    OrderEnterService orderEnterService;

    @Autowired
    ProfitListService profitListService;

    @RequestMapping("/init")
    public String profitListInit(Model model, ProfitDto profitDto) {
        List<CustomerDto> customerList = orderEnterService.customerNameList();
        List<ProfitDto> profitInfoList = profitListService.profitInfoList(profitDto);
        String customerPaySum = profitListService.profitSumInfo(profitDto);
        model.addAttribute("customerList", customerList);
        model.addAttribute("profitInfoList", profitInfoList);
        model.addAttribute("customerPaySum", customerPaySum);
        if ("1".equals(profitDto.getUpdateFlg())) {
            return "order/profit-list::tableUpdate";
        } else {
            return "order/profit-list";
        }
    }
    @RequestMapping("/insertProfitInfo")
    @ResponseBody
    public Map<String, Object> profitInfoInsert(Model model, ProfitDto profitDto) {
        Map<String, Object> res = new HashMap<>();
        profitListService.profitInfoInsert(profitDto);
        res.put("code", 200);
        return res;
    }
}
